ShortcutData *sdata = data;
g_object_unref (sdata->shortcut);
- g_free (sdata);
}
static gboolean
gboolean enable_mnemonics)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
- guint i;
- GSList *shortcuts = NULL;
- GSList *l;
+ int i, p;
+ GArray *shortcuts = NULL;
gboolean has_exact = FALSE;
gboolean retval = FALSE;
- for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
+ for (i = 0, p = g_list_model_get_n_items (self->shortcuts); i < p; i++)
{
GtkShortcut *shortcut;
ShortcutData *data;
case GDK_KEY_MATCH_EXACT:
if (!has_exact)
{
- g_slist_free_full (shortcuts, shortcut_data_free);
- shortcuts = NULL;
+ if (shortcuts)
+ g_array_set_size (shortcuts, 0);
}
has_exact = TRUE;
break;
continue;
}
- data = g_new0 (ShortcutData, 1);
+ if (G_UNLIKELY (!shortcuts))
+ {
+ shortcuts = g_array_sized_new (FALSE, TRUE, sizeof (ShortcutData), 8);
+ g_array_set_clear_func (shortcuts, shortcut_data_free);
+ }
+
+ g_array_set_size (shortcuts, shortcuts->len + 1);
+ data = &g_array_index (shortcuts, ShortcutData, shortcuts->len - 1);
data->shortcut = shortcut;
data->index = index;
data->widget = widget;
-
- shortcuts = g_slist_append (shortcuts, data);
}
- for (l = shortcuts; l; l = l->next)
+ if (!shortcuts)
+ return retval;
+
+ for (i = shortcuts->len - 1, p = shortcuts->len; i >= 0; i--)
{
- ShortcutData *data = l->data;
+ const ShortcutData *data = &g_array_index (shortcuts, ShortcutData, i);
if (gtk_shortcut_action_activate (gtk_shortcut_get_action (data->shortcut),
- shortcuts->next == NULL ? GTK_SHORTCUT_ACTION_EXCLUSIVE : 0,
+ i == p - 1 ? GTK_SHORTCUT_ACTION_EXCLUSIVE : 0,
data->widget,
gtk_shortcut_get_arguments (data->shortcut)))
{
}
}
- g_slist_free_full (shortcuts, shortcut_data_free);
+ g_array_free (shortcuts, TRUE);
return retval;
}